package com.clj.cloud.authorization_server.oauth2.enhancer;

import java.util.Map;

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import com.google.common.collect.Maps;

/**
 * 自定义token携带内容
 * @author Administrator
 *
 */
public class CustomTokenEnhancer implements TokenEnhancer{

	@Override
	public OAuth2AccessToken enhance(OAuth2AccessToken accessToken,
			OAuth2Authentication authentication) {
			Map<String,Object> additionalInfo = Maps.newHashMap();
			//自定义token内容，加入组织机构信息
			additionalInfo.put("organization", authentication.getName());
			((DefaultOAuth2AccessToken)accessToken).setAdditionalInformation(additionalInfo);
		return accessToken;
	}

}
